﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace MoFramework
{
    [RequireComponent(typeof(Canvas))]
    abstract public class BaseUIForm : MonoBehaviour
    {
        public bool mutual;
        /// <summary>
        /// 这一个UI预计需要占用的层数
        /// </summary>
        public int requireLayer = 5;
        Canvas m_Canvas;

        ChildrenDictionary m_ObjDict = new ChildrenDictionary();

        public int layerID
        {
            get
            {
                return m_Canvas.sortingLayerID;
            }
        }
        public string layerName
        {
            get
            {
                return m_Canvas.sortingLayerName;
            }
        }
        public int order
        {
            get
            {
                return m_Canvas.sortingOrder;
            }
            set
            {
                m_Canvas.sortingOrder = value;
            }
        }

        object m_Data;

        protected virtual void Awake()
        {
            m_Canvas = GetComponent<Canvas>();
            m_ObjDict.Init(gameObject);
        }
        protected virtual void Start()
        { }
        protected virtual void OnEnable()
        {

        }

        public GameObject GetObj(string name)
        {
            return m_ObjDict.GetObj(name);
        }
        public T GetObjComponent<T>(string name,bool addWhenDontExist = true) where T:Component
        {
            return m_ObjDict.GetComponent<T>(name,addWhenDontExist);
        }
        public void Open(object data = null)
        {
            m_Data = data;
            StartOpen();
        }
        public void Close()
        {
            gameObject.SetActive(false);
        }

        virtual public void StartOpen()
        {
            gameObject.SetActive(true);
        }
        virtual public void StartClose()
        {
            Close();
        }
    }
}

